package demo1;

class Money {
    public double money;

}
class Student implements Cloneable {
    //Cloneable这个接口里面没有什么东西，所以这个 接口 叫做 标记接口
    public int age;

    public Money m = new Money();
    public Student(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();//这里的返回值是父类
        //对clone的重写
    }
}
public class Test {

    public static void main(String[] args) throws CloneNotSupportedException {
        Student student1 = new Student(10);

        student1.m.money = 19.9;


        Student student2 = (Student) student1.clone();

        System.out.println(student1.m.money);
        System.out.println(student2.m.money);

    }


    public static void main1(String[] args) throws CloneNotSupportedException {
        Student student1 = new Student(10);
        Student student2 = (Student) student1.clone();//这里就会用到向下转型
        System.out.println(student1);
        System.out.println(student2);
    }
}
